package com.itrip.service.impl;

import com.itrip.dao.ex.HotelMapperEX;
import com.itrip.document.Hotel;
import com.itrip.dto.HotelRoomDTO;
import com.itrip.repository.HotelRepository;
import com.itrip.service.HotelService;
import org.apache.solr.client.solrj.SolrServerException;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.io.IOException;
import java.util.List;
@Service
public class HotelServiceImpl implements HotelService {
    @Resource
    private HotelRepository hotelRepository;

    @Resource
    private HotelMapperEX hotelMapperEX;

    @Override
    @Cacheable(value = "hotel",key = "'getHotelByQuery'+#keyword+','+#pageNow+','+#pageSize")
    public List<Hotel> getHotelByQuery(String keyword, Integer pageNow, Integer pageSize) throws IOException, SolrServerException {
        return hotelRepository.getHotelByQuery(keyword,(pageNow-1)*pageSize,pageSize);
    }

    @Override
    public Long getHotelCount(String keyword) throws IOException, SolrServerException {
        return hotelRepository.getHotelCount(keyword);
    }

    @Override
    @Cacheable(value = "hotelRoom",key = "'getHotelRoomList'+#id")
    public HotelRoomDTO getHotelRoomList(Integer id) {
        return hotelMapperEX.getHotelRoomList(id);
    }
}
